//jqGrid的配置信息
$.jgrid.defaults.width = 1000;
$.jgrid.defaults.responsive = true;
$.jgrid.defaults.styleUI = 'Bootstrap';

//工具集合Tools
window.T = {};

// 获取请求参数
// 使用示例
// location.href = http://localhost:8080/index.html?id=123
// T.p('id') --> 123;
var url = function(name) {
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r!=null)return  unescape(r[2]); return null;
};
T.p = url;

//全局配置
$.ajaxSetup({
	dataType: "json",
	cache: false
});

//重写alert
window.alert = function(msg, callback){
	parent.layer.alert(msg, function(index){
		parent.layer.close(index);
		if(typeof(callback) === "function"){
			callback("ok");
		}
	});
}

//重写confirm式样框
window.confirm = function(msg, callback){
	parent.layer.confirm(msg, {btn: ['确定','取消']},
	function(){//确定事件
		if(typeof(callback) === "function"){
			callback("ok");
		}
	});
}

//选择一条记录
function getSelectedRow() {
    var grid = $("#jqGrid");
    var rowKey = grid.getGridParam("selrow");
    if(!rowKey){
    	alert("请选择一条记录");
    	return ;
    }
    
    var selectedIDs = grid.getGridParam("selarrrow");
    if(selectedIDs.length > 1){
    	alert("只能选择一条记录");
    	return ;
    }
    
    return selectedIDs[0];
}

//选择多条记录
function getSelectedRows() {
    var grid = $("#jqGrid");
    var rowKey = grid.getGridParam("selrow");
    if(!rowKey){
    	alert("请选择一条记录");
    	return ;
    }
    
    return grid.getGridParam("selarrrow");
}

function getDictInfo1(cellvalue, options, rowObject){
    if(cellvalue==""||cellvalue==null){
        return "";
    }
    var val = "";
    $.ajax({
        type: "POST",
        url: "../sysdict/info/"+cellvalue,
        async:false,
        success: function(r){
            val = r.sysDict.value ;
        }
    });
    return val;
}

function getDictInfo(cellvalue, options, rowObject){

    if(cellvalue==""||cellvalue==null){
        return "";
    }
    var val = "";
    for(var i=0; i<sys_dict.length; i++){
        if(sys_dict[i].value==cellvalue){
            val=sys_dict[i].label;
        }
        if(val==undefined||val==""){
            val=cellvalue;
        }
    }
    return val;
}

function queryByIndex(cellvalue){
    var val = null;
    $.ajax({
        type: "POST",
        url: "../customsettlement/queryByIndex/"+cellvalue,
        async:false,
        success: function(r){
            val = r.indexToValue ;
        }
    });
    return val;
}




function pistatus(v){
    if(v==""||v==null){
        return "<font  color='green'>未提交</font>";
    }
    else if(v=="1"){
        return "<font  color='red'>一级主管审批</font>";
    }else if(v=="2"){
        return "<font  color='red'>二级主管审批</font>";
    }else if(v=="3"){
        return "<font  color='red'>三级主管审批</font>";
    }else if(v=="0"){
        return "<font  color='green'>审批完成</font>";
    }else if(v=="10"){
        return "<font  color='red'>被拒绝</font>";
    }
}
var sys_dict;
function getDict(){
    var val;
    $.ajax({
        type: "POST",
        url: "../sysdict/queryDictList/",
        async:false,
        success: function(r){
            val = r.sysDictList ;
        }
    });
    return val;
}

function bindDate(value,id,v){
    vm[v][id]=value;

}

$(function () {
        sys_dict = getDict();

    $("#find_btn").click(function(){
        var popUser_name = $("#popUser_name").val();
        // var popUser_name = encodeURI(encodeURI($("#popUser_name").val()));
        $("#popUserGrid").jqGrid('setGridParam',{
            url: '../sys/user/list',
            postData:{'userdesc':popUser_name}, //发送数据
            page:1
        }).trigger("reloadGrid"); //重新载入 }
    });

    $("#findsettlement_btn").click(function(){
        var popUser_name = $("#popUser_name").val();
        var page = $("#popSettlementGrid").jqGrid('getGridParam','page');
        $("#popSettlementGrid").jqGrid('setGridParam',{
            url: '../customsettlement/list',
            postData:{'settlementName':popUser_name}, //发送数据
            page:page
        }).trigger("reloadGrid"); //重新载入 }
    });
})